const commonjs = require('@rollup/plugin-commonjs')
const resolve = require('@rollup/plugin-node-resolve').default
const sourcemaps = require('rollup-plugin-sourcemaps')

const external = [
  'estimo',
  'pretty-bytes',
  'chalk',
  'table',
  'lighthouse/types/externs',
  'lighthouse/types/artifacts',
  'debug',
  'webpack',
  'lodash',
  'puppeteer-core',
  'lodash/first',
  'nanoid',
  'react',
  'rxjs',
  'rxjs/operators',
  'events',
  'assert',
  'buffer',
  'string_decoder',
  '@nestjs/common',
  '@nestjs/microservices',
  '@byted-service/eventbus',
  'clipanion',
  'form-data',
  'node-fetch',
  'htmlparser2',
  'react-router',

  // node builtin
  'util',
  'fs',
  'path',
  'os',
  'crypto',
  'url',
  'https',
  'http',
  'stream',
  'zlib',
  'child_process',
]

const defaultConfig = [
  {
    input: `./esm/index.js`,
    external,
    plugins: [
      sourcemaps(),
      commonjs(),
      resolve({
        preferBuiltins: true,
      }),
    ],
    output: [
      {
        file: `./dist/index.cjs.js`,
        format: 'cjs',
        sourcemap: true,
      },
      {
        file: `./dist/index.esm.js`,
        format: 'esm',
        sourcemap: true,
      },
    ],
  },
]

module.exports = {
  defaultConfig,
}
